package OrdersSystem;

import static org.junit.Assert.*;
import java.sql.Time;
import java.util.Calendar;
import java.util.Date;
import org.junit.Test;

public class OrderTest {

	@Test
	public void testTestValidateOrder() {
		
		// Test Case #1  Correct Data
		Calendar c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 3);
		Date requestedDeliveryDate = c.getTime();		
		Time requestedDeliveryTime = new Time(100);
		System.out.println("Test Case #1: Order with valid data. Should validate.");
		Order order = new Order(111, "Edinburgh", 1, requestedDeliveryDate, requestedDeliveryTime, 1, 8, "" );
		boolean testValidation = order.testValidateOrder();
		System.out.println("TEST RESULT: Validation = " + testValidation);
		System.out.println();
		assertEquals("Result", true, testValidation);
		
		// Test Case #2 Incorrect Date >7 days
		c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 8);
		requestedDeliveryDate = c.getTime();
		order = new Order(111, "Edinburgh", 1, requestedDeliveryDate, requestedDeliveryTime, 1, 10, "" );
		System.out.println("Test Case #2: Order with incorrect date (>7 days). Should not validate.");
		testValidation = order.testValidateOrder();
		System.out.println("TEST RESULT: Validation = " + testValidation);
		System.out.println();
		assertEquals("Result", false, testValidation);
		
		//Test Case #3 Incorrect quantity 1.25
		c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 3);
		requestedDeliveryDate = c.getTime();
		order = new Order(111, "Edinburgh", 1, requestedDeliveryDate, requestedDeliveryTime, 1, (float) 1.25, "" );
		System.out.println("Test Case #3: Order with incorrect quantity (1.25). Should not validate.");
		testValidation = order.testValidateOrder();
		System.out.println("TEST RESULT: Validation = " + testValidation);
		System.out.println();
		assertEquals("Result", false, testValidation);
		
		//Test Case #4 Incorrect Date <24h
		requestedDeliveryDate = new Date();
		order = new Order(111, "Edinburgh", 1, requestedDeliveryDate, requestedDeliveryTime, 1, 10, "" );
		System.out.println("Test Case #4: Order with incorrect date (<24h). Should not validate.");
		testValidation = order.testValidateOrder();
		System.out.println("TEST RESULT: Validation = " + testValidation);
		System.out.println();
		assertEquals("Result", false, testValidation);
		
		//Test Case #5 Date <24 and quantity 1.25
		c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 8);
		requestedDeliveryDate = c.getTime();
		order = new Order(111, "Edinburgh", 1, requestedDeliveryDate, requestedDeliveryTime, 1, (float)1.25, "" );
		System.out.println("Test Case #5: Order with incorrect date (<24 days) and quantity (1.25). Should not validate.");
		testValidation = order.testValidateOrder();
		System.out.println("TEST RESULT: Validation = " + testValidation);
		System.out.println();
		assertEquals("Result", false, testValidation);
	}

	@Test
	public void testTestConfirmOrder() {
		// Test Case #6 Correct Data in the order, order should be confirmed
		Calendar c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 3);
		Date requestedDeliveryDate = c.getTime();		
		Time requestedDeliveryTime = new Time(100);
		System.out.println("Test Case #6: Order with odd number for ID. Should be confirmed.");
		Order order = new Order(111, "Edinburgh", 1, requestedDeliveryDate, requestedDeliveryTime, 1, 8, "" );
		boolean testConfirmation = order.testConfirmOrder();
		System.out.println("TEST RESULT: Confirmation = " + testConfirmation);
		System.out.println();
		assertEquals("Result", true, testConfirmation);
		
		//Test Case #7 Correct Data in the order, order should not validate
		order = new Order(111, "Edinburgh", 1, requestedDeliveryDate, requestedDeliveryTime, 1, 8, "" );
		System.out.println("Test Case #7: Order with even number for ID. Should not be confirmed.");
		testConfirmation = order.testConfirmOrder();
		System.out.println("TEST RESULT: Confirmation = " + testConfirmation);
		System.out.println();
		assertEquals("Result", false, testConfirmation);
	}

}
